/***************************************************************************
 创建者：华磊
 开始时间：         : 2020.12.15
 copyright            : (C) 深圳市华友高科有限公司
 修改说明：（每次有修改就添加一条，带有 修改人，修改时间，修改描述）

 ***************************************************************************
 *   循环指令属性编辑视窗
*                                                                         *
 ***************************************************************************/
#include "forinstructiondelegate.h"
#include <QDebug>

ForInstructionDelegate::ForInstructionDelegate(QWidget *parent):
    QObject(parent)
{
}


void ForInstructionDelegate::initialView()
{
    forInstructionView->forInstructionHead = "FOR";
    forInstructionView->forInstructionTail = "ENDFOR";
    forInstructionView->selectHeadFlag = 1;
    forInstructionView->selectTailFlag = 1;
    forInstructionView->dealValueType = "TO ";
    forInstructionView->dealValueTypeFlag = 0;
    forInstructionView->rIndex = "1";
    forInstructionView->initialValue = "1";
    forInstructionView->targetValue = "1";
    forInstructionView->initialValueTypeIndex = 1;
    forInstructionView->targetValueTypeIndex = 1;
    forInstructionView->note = "";
    forInstructionView->initialData = "1";
    forInstructionView->targetData = "1";

    //forInstructionView->updateView();
}

void ForInstructionDelegate::selectForHeadSlot()
{
    forInstructionView->selectHeadFlag = 1;

    forInstructionView->updateView();

    qDebug("select for head");
}

void ForInstructionDelegate::selectFortailSlot()
{
    forInstructionView->selectTailFlag = 1;
    forInstructionView->updateView();

    qDebug("select for tail");
}

void ForInstructionDelegate::selectToTypeSlot()
{
    forInstructionView->dealValueTypeFlag = 0;
    forInstructionView->updateView();

    qDebug("select to");
}

void ForInstructionDelegate::selectDownTypeSlot()
{
    forInstructionView->dealValueTypeFlag = 1;
    forInstructionView->updateView();

    qDebug("select down");
}

void ForInstructionDelegate::clearNoteSlot()
{
    forInstructionView->note.clear();
    qDebug("clear note");
}

void ForInstructionDelegate::finishEditInstructionSlot()
{
    QString str = "FOR";
    forInstructionView->forInstructionHead = str + " " + "R[" +  forInstructionView->rIndex + "]" + "=";

    if(EM_FOR_VALUE_TYPE_CONSTANT == forInstructionView->initialValueTypeIndex)
    {
        forInstructionView->initialValue = forInstructionView->initialData;
    }
    else if(EM_FOR_VALUE_TYPE_R == forInstructionView->initialValueTypeIndex)
    {
        forInstructionView->initialValue = "R[" + forInstructionView->initialData + "]";
    }
    else if(EM_FOR_VALUE_TYPE_AR == forInstructionView->initialValueTypeIndex)
    {
        forInstructionView->initialValue = "AR[" + forInstructionView->initialData + "]";
    }

    if(0 == forInstructionView->dealValueTypeFlag)
    {
        forInstructionView->dealValueType = "TO";
    }
    else
    {
        forInstructionView->dealValueType = "DOWNTO";
    }

    if(EM_FOR_VALUE_TYPE_CONSTANT == forInstructionView->targetValueTypeIndex)
    {
        forInstructionView->targetValue = forInstructionView->targetData;
    }
    else if(EM_FOR_VALUE_TYPE_R == forInstructionView->targetValueTypeIndex)
    {
        forInstructionView->targetValue = "R[" + forInstructionView->targetData + "]";
    }
    else if(EM_FOR_VALUE_TYPE_AR == forInstructionView->targetValueTypeIndex)
    {
        forInstructionView->targetValue = "AR[" + forInstructionView->targetData + "]";
    }

     forInstructionView->forInstructionHead += forInstructionView->initialValue + " " + forInstructionView->dealValueType
             + " " + forInstructionView->targetValue + "; " + "//" + forInstructionView->note;
}
